<!DOCTYPE html>
<html lang="en">

<!-- Head tag -->
<head><meta name="generator" content="Hexo 3.8.0">

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!--Description-->

    

    
        <meta name="description" content="一、mdia( Media Box)mdia是一个contain box,主要包含mdhd(Media Header Box), hdlr(Handler Reference Box)和minf(Media Information Box),包含着解码track的关键信息。1200 00 08 EC">
    

    <!--Author-->
    
        <meta name="author" content="Cyrus">
    

    <!--Open Graph Title-->
    
        <meta property="og:title" content="MP4格式解析四 mdia-&gt;mdhd &amp;&amp; mdia-&gt;hdlr">
    

    <!--Open Graph Description-->
    
        <meta property="og:description" content="一、mdia( Media Box)mdia是一个contain box,主要包含mdhd(Media Header Box), hdlr(Handler Reference Box)和minf(Media Information Box),包含着解码track的关键信息。1200 00 08 EC">
    

    <!--Open Graph Site Name-->
        <meta property="og:site_name" content="Cyrus的技术空间">

    <!--Type page-->
    
        <meta property="og:type" content="article">
    

    <!--Page Cover-->
    
    
        <meta property="og:image" content="http://cyrus_huang.gitee.io/bloghttp://www.codeblocq.com/assets/projects/hexo-theme-clean-blog/img/home-bg.jpg">
    

        <meta name="twitter:card" content="summary_large_image">

    

    
        <meta name="twitter:image" content="http://cyrus_huang.gitee.io/bloghttp://www.codeblocq.com/assets/projects/hexo-theme-clean-blog/img/home-bg.jpg">
    

    <!-- Title -->
    
    <title>MP4格式解析四 mdia-&gt;mdhd &amp;&amp; mdia-&gt;hdlr - Cyrus的技术空间</title>

    <!-- Bootstrap Core CSS -->
    <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link rel="stylesheet" href="/blog/css/style.css">

    <!-- Custom Fonts -->
    <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    <link href="//fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic" rel="stylesheet" type="text/css">
    <link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800" rel="stylesheet" type="text/css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="//oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="//oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

    <!-- Gallery -->
    <link href="//cdnjs.cloudflare.com/ajax/libs/featherlight/1.3.5/featherlight.min.css" type="text/css" rel="stylesheet">

    <!-- Google Analytics -->
    


    <!-- favicon -->
    

</head>


<body>

    <!-- Menu -->
    <!-- Navigation -->
<nav class="navbar navbar-default navbar-custom navbar-fixed-top">
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header page-scroll">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="/blog/">Cyrus的技术空间</a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav navbar-right">
                
                    <li>
                        <a href="/blog/">
                            
                                Home
                            
                        </a>
                    </li>
                
                    <li>
                        <a href="/blog/archives">
                            
                                Archives
                            
                        </a>
                    </li>
                
                    <li>
                        <a href="/blog/tags">
                            
                                Tags
                            
                        </a>
                    </li>
                
                    <li>
                        <a href="/blog/categories">
                            
                                Categories
                            
                        </a>
                    </li>
                
                    <li>
                        <a href="https://github.com/klugjo/hexo-theme-clean-blog">
                            
                                <i class="fa fa-github fa-stack-2x"></i>
                            
                        </a>
                    </li>
                
            </ul>
        </div>
        <!-- /.navbar-collapse -->
    </div>
    <!-- /.container -->
</nav>

    <!-- Main Content -->
    <!-- Page Header -->
<!-- Set your background image for this header in your post front-matter: cover -->

<header class="intro-header" style="background-image: url('http://www.codeblocq.com/assets/projects/hexo-theme-clean-blog/img/home-bg.jpg')">
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <div class="post-heading">
                    <h1>MP4格式解析四 mdia->mdhd && mdia->hdlr</h1>
                    
                    <span class="meta">
                        <!-- Date and Author -->
                        
                            Posted by Cyrus on
                        
                        
                            2019-08-15
                        
                    </span>
                </div>
            </div>
        </div>
    </div>
</header>

<!-- Post Content -->
<article>
    <div class="container">
        <div class="row">

            <!-- Tags and categories -->
           
                <div class="col-lg-4 col-lg-offset-2 col-md-5 col-md-offset-1 post-tags">
                    
                        


<a href="/blog/tags/MP4/">#MP4</a>


                    
                </div>
                <div class="col-lg-4 col-md-5 post-categories">
                    
                        

<a href="/blog/categories/音视频/">音视频</a>

                    
                </div>
            

            <!-- Gallery -->
            

            <!-- Post Main Content -->
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <h3 id="一、mdia-Media-Box"><a href="#一、mdia-Media-Box" class="headerlink" title="一、mdia( Media Box)"></a>一、mdia( Media Box)</h3><p>mdia是一个contain box,主要包含mdhd(Media Header Box), hdlr(Handler Reference Box)和minf(Media Information Box),包含着解码track的关键信息。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">00 00 08 EC: size 2284 </span><br><span class="line">6D 64 69 61: mdia</span><br></pre></td></tr></table></figure></p>
<h3 id="二、mdhd-Media-Header-Box"><a href="#二、mdhd-Media-Header-Box" class="headerlink" title="二、mdhd(Media Header Box)"></a>二、mdhd(Media Header Box)</h3><p><img src="http://cyrus_huang.gitee.io/blog/2019/08/15/MP4格式解析四-mdia-mdhd-mdia-hdlr/mdhd_1.png" alt=""><br>解析伪代码<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">aligned(8) class MediaHeaderBox extends FullBox(‘mdhd’, version, 0) </span><br><span class="line">	&#123;</span><br><span class="line">		if (version==1)</span><br><span class="line">		&#123;</span><br><span class="line">			unsigned int(64) creation_time;</span><br><span class="line">			unsigned int(64) modification_time;</span><br><span class="line">			unsigned int(32) timescale;</span><br><span class="line">			unsigned int(64) duration;</span><br><span class="line">		&#125;</span><br><span class="line">		else</span><br><span class="line">		&#123; // version==0</span><br><span class="line">			unsigned int(32) creation_time;</span><br><span class="line">			unsigned int(32) modification_time;</span><br><span class="line">			unsigned int(32) timescale;</span><br><span class="line">			unsigned int(32) duration;</span><br><span class="line">		&#125;</span><br><span class="line">		bit(1) pad = 0;</span><br><span class="line">		unsigned int(5)[3] language; // ISO-639-2/T language code</span><br><span class="line">		unsigned int(16) pre_defined = 0;</span><br><span class="line">	&#125;</span><br><span class="line">    </span><br><span class="line"></span><br><span class="line">creation_time: track中数据的创建时间,多同‘tkhd’中creation_time.</span><br><span class="line">modification_time: track中数据的修改时间,多同‘tkhd’中modification_time.</span><br><span class="line">timescale: 媒体中时间尺度. 通常和&apos;mvhd&apos;中的timescale不同,精度更高.</span><br><span class="line">duration: 媒体的长度(时间尺度表示).</span><br><span class="line">language：语言,符合ISO-639-2/T标准.</span><br></pre></td></tr></table></figure></p>
<p>下面看一下具体数据解析：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">00 00 00 20 6D 64 68 64 00 00 00 00 D9 70 A8 7B ; ... mdhd.....p.&#123;</span><br><span class="line">D9 70 A8 7B 00 00 BB 80 00 06 A0 00 55 C4 00 00 ; .p.&#123;.......U...</span><br><span class="line"></span><br><span class="line">======================== 解析 ========================</span><br><span class="line">00 00 00 20： size 32</span><br><span class="line">6D 64 68 64:  mdhd</span><br><span class="line">00 00 00 00: version = 0, flag = 0</span><br><span class="line">D9 70 A8 7B: creation_time</span><br><span class="line">D9 70 A8 7B: modification_time</span><br><span class="line">00 00 BB 80: timescale 48000</span><br><span class="line">00 06 A0 00: duration 434176  duration/timescale = 434176/48000=9s</span><br><span class="line">55 C4: language und(0X15+0x60, 0X0E+0x60, 0X04+0x60)</span><br><span class="line">	0101 0101 1100 0100 -&gt;10101(0x15)  01110(0x0E) 00100(0x04)</span><br></pre></td></tr></table></figure></p>
<h3 id="hdlr-Handler-Reference-Box"><a href="#hdlr-Handler-Reference-Box" class="headerlink" title="hdlr(Handler Reference Box)"></a>hdlr(Handler Reference Box)</h3><p>handler, declares the media (handler) type<br>可获取track类型信息，主要是有字段handler_type(uint32_t)区分，具体含义如下：</p>
<ul>
<li>‘vide’ Video track</li>
<li>‘soun’ Audio track</li>
<li>‘hint’ Hint track</li>
</ul>
<p><img src="http://cyrus_huang.gitee.io/blog/2019/08/15/MP4格式解析四-mdia-mdhd-mdia-hdlr/hdlr_1.png" alt=""><br>下面看一下具体数据解析：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">00 00 00 31 68 64 6C 72 00 00 00 00 00 00 00 00 ; ...1hdlr........</span><br><span class="line">73 6F 75 6E 00 00 00 00 00 00 00 00 00 00 00 00 ; soun............</span><br><span class="line">43 6F 72 65 20 4D 65 64 69 61 20 41 75 64 69 6F ; Core Media Audio</span><br><span class="line">00        ; .</span><br><span class="line"></span><br><span class="line">======================== 解析 ========================</span><br><span class="line">00 00 00 31: size 49</span><br><span class="line">68 64 6C 72: hdlr </span><br><span class="line">00 00 00 00: version flag 都为0</span><br><span class="line">00 00 00 00: component type: 全0</span><br><span class="line">73 6F 75 6E: component subtype soun 代表该track为 audio track</span><br><span class="line">00 00 00 00: Component manufacturer 。 Reserved. Set to 0.</span><br><span class="line">00 00 00 00: Component flags。Reserved. Set to 0.</span><br><span class="line">00 00 00 00  Component flags mask。Reserved. Set to 0。</span><br><span class="line">43 6F 72 65 20 4D 65 64 69 61 20 41 75 64 69 6F 00:Name（Core Media Audio.）</span><br></pre></td></tr></table></figure></p>
<p>再看一下视频的hdlr数据：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">00 00 00 31 68 64 6C 72 00 00 00 00 00 00 00 00 ; ...1hdlr........</span><br><span class="line">76 69 64 65 00 00 00 00 00 00 00 00 00 00 00 00 ; vide............</span><br><span class="line">43 6F 72 65 20 4D 65 64 69 61 20 56 69 64 65 6F ; Core Media Video</span><br><span class="line">00                                              ; .</span><br><span class="line"></span><br><span class="line">======================== 解析 ========================</span><br><span class="line">前面与音频相同</span><br><span class="line">76 69 64 65： component subtype vide</span><br><span class="line">43 6F 72 65 20 4D 65 64 69 61 20 56 69 64 65 6F 00: Name(Core Media Video.)</span><br></pre></td></tr></table></figure></p>


                
            </div>

            <!-- Comments -->
            
                <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                    


                </div>
            
        </div>
    </div>
</article>

    <!-- Footer -->
    <hr>

<!-- Footer -->
<footer>
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <ul class="list-inline text-center">
                    

                    

                    
                        <li>
                            <a href="https://github.com/klugjo/hexo-theme-clean-blog" target="_blank">
                                <span class="fa-stack fa-lg">
                                    <i class="fa fa-circle fa-stack-2x"></i>
                                    <i class="fa fa-github fa-stack-1x fa-inverse"></i>
                                </span>
                            </a>
                        </li>
                    

                    

                    

                    
                </ul>
                <p class="copyright text-muted">&copy; 2020 Cyrus<br></p>
                <p class="copyright text-muted">Original Theme <a target="_blank" href="http://startbootstrap.com/template-overviews/clean-blog/">Clean Blog</a> from <a href="http://startbootstrap.com/" target="_blank">Start Bootstrap</a></p>
                <p class="copyright text-muted">Adapted for <a target="_blank" href="https://hexo.io/">Hexo</a> by <a href="http://www.codeblocq.com/" target="_blank">Jonathan Klughertz</a></p>
                <p class="copyright text-muted"><a href="http://www.beian.miit.gov.cn">粤ICP备18110122号-1</a></p>
            </div>
        </div>
    </div>
</footer>


    <!-- After footer scripts -->
    
<!-- jQuery -->
<script src="//code.jquery.com/jquery-2.1.4.min.js"></script>

<!-- Bootstrap -->
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

<!-- Gallery -->
<script src="//cdnjs.cloudflare.com/ajax/libs/featherlight/1.3.5/featherlight.min.js" type="text/javascript" charset="utf-8"></script>

<!-- Disqus Comments -->



</body>

</html>